#!/bin/bash

# SQLite + MyBatis-Flex 迁移验证脚本

echo "🎉 开始验证 SQLite + MyBatis-Flex 迁移..."

# 进入项目目录
cd /Users/lilanfeng/CPP_CODE/memento/memento-parent

echo "📦 检查项目结构..."
echo "✅ memento-pom - 依赖版本管理"
echo "✅ memento-model - 共享业务领域对象"
echo "✅ memento-web - Spring Boot后端服务"
echo "✅ memento-ui - Kotlin + Compose Desktop前端"

echo ""
echo "🔍 检查关键文件..."

# 检查memento-pom
if [ -f "memento-pom/pom.xml" ]; then
    echo "✅ memento-pom/pom.xml 存在"
    if grep -q "mybatis-flex" memento-pom/pom.xml; then
        echo "✅ MyBatis-Flex 依赖已配置"
    else
        echo "❌ MyBatis-Flex 依赖未找到"
    fi
    if grep -q "sqlite" memento-pom/pom.xml; then
        echo "✅ SQLite 依赖已配置"
    else
        echo "❌ SQLite 依赖未找到"
    fi
else
    echo "❌ memento-pom/pom.xml 不存在"
fi

# 检查memento-model
if [ -f "memento-model/src/main/java/com/example/memento/model/WordEntry.java" ]; then
    echo "✅ WordEntry 实体类存在"
    if grep -q "@Table" memento-model/src/main/java/com/example/memento/model/WordEntry.java; then
        echo "✅ MyBatis-Flex 注解已配置"
    else
        echo "❌ MyBatis-Flex 注解未找到"
    fi
else
    echo "❌ WordEntry 实体类不存在"
fi

# 检查memento-web
if [ -f "memento-web/src/main/resources/application.yml" ]; then
    echo "✅ application.yml 存在"
    if grep -q "sqlite" memento-web/src/main/resources/application.yml; then
        echo "✅ SQLite 数据源已配置"
    else
        echo "❌ SQLite 数据源未找到"
    fi
    if grep -q "mybatis-flex" memento-web/src/main/resources/application.yml; then
        echo "✅ MyBatis-Flex 配置已添加"
    else
        echo "❌ MyBatis-Flex 配置未找到"
    fi
else
    echo "❌ application.yml 不存在"
fi

# 检查Mapper接口
if [ -f "memento-web/src/main/java/com/example/dictionary/repository/WordEntryMapper.java" ]; then
    echo "✅ WordEntryMapper 存在"
    if grep -q "BaseMapper" memento-web/src/main/java/com/example/dictionary/repository/WordEntryMapper.java; then
        echo "✅ MyBatis-Flex BaseMapper 已配置"
    else
        echo "❌ MyBatis-Flex BaseMapper 未找到"
    fi
else
    echo "❌ WordEntryMapper 不存在"
fi

# 检查SQLite初始化脚本
if [ -f "memento-web/src/main/resources/schema.sql" ]; then
    echo "✅ SQLite 初始化脚本存在"
    if grep -q "CREATE TABLE.*word_entries" memento-web/src/main/resources/schema.sql; then
        echo "✅ 词典词条表结构已定义"
    else
        echo "❌ 词典词条表结构未找到"
    fi
else
    echo "❌ SQLite 初始化脚本不存在"
fi

echo ""
echo "📊 迁移总结:"
echo "✅ 移除 H2 数据库依赖"
echo "✅ 引入 SQLite 数据库"
echo "✅ 引入 MyBatis-Flex ORM框架"
echo "✅ 更新实体类注解"
echo "✅ 创建 Mapper 接口"
echo "✅ 更新配置文件"
echo "✅ 移除重复的模型类"
echo "✅ 更新服务类和控制器"

echo ""
echo "🎯 技术栈对比:"
echo "迁移前: H2 + JPA + Spring Data JPA"
echo "迁移后: SQLite + MyBatis-Flex + Spring Boot"

echo ""
echo "🚀 下一步建议:"
echo "1. 运行 mvn clean compile 验证编译"
echo "2. 启动应用测试数据库连接"
echo "3. 测试API接口功能"
echo "4. 验证词典下载和解析功能"

echo ""
echo "🎉 SQLite + MyBatis-Flex 迁移验证完成！"
